android 对话框背景虚化效果,android – 对话框后面的模糊背景 |
您所在的位置:网站首页 › android studio背景图片虚化 › android 对话框背景虚化效果,android – 对话框后面的模糊背景 |
我希望在它下面有模糊屏幕的对话框,所以我拍摄活动的“截图”,模糊它并将对话框窗口的背景设置为BitmapDrawable.奇怪的是,对话框不再以屏幕为中心,即使调用了setCanceledOnTouchOutside(true),外部对话框也不会忽略它. 问题是:为什么这不起作用?分别如何创建模糊背景的对话框? public class BlurDialog extends DialogFragment { public BlurDialog() { } public static BlurDialog newInstance() { return new BlurDialog(); } @Override public Dialog onCreateDialog(Bundle savedInstanceState) { final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()) .setTitle("Title") .setMessage("Message") .setPositiveButton("OK", null) .setNegativeButton("Cancel", null) .create(); alertDialog.setCanceledOnTouchOutside(true); View view = getActivity().getWindow().getDecorView(); view.setDrawingCacheEnabled(true); Bitmap b1 = view.getDrawingCache(); Rect frame = new Rect(); getActivity().getWindow().getDecorView().getWindowVisibleDisplayFrame(frame); int statusBarHeight = frame.top; final int width = getActivity().getWindow().getDecorView().getWidth(); final int height = getActivity().getWindow().getDecorView().getHeight(); Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height-statusBarHeight); //define this only once if blurring multiple times RenderScript rs = RenderScript.create(getActivity()); //this will blur the bitmapOriginal with a radius of 8 and save it in bitmapOriginal final Allocation input = Allocation.createFromBitmap(rs, b); //use this constructor for best performance, because it uses USAGE_SHARED mode which reuses memory final Allocation output = Allocation.createTyped(rs, input.getType()); final ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(8f); script.setInput(input); script.forEach(output); output.copyTo(b); alertDialog.getWindow().setBackgroundDrawable(new BitmapDrawable(getResources(), b)); return alertDialog; } } |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |